package recolhalixo;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Random;
import java.util.Stack;

import jadex.bdi.runtime.IGoal;
import jadex.bdi.runtime.IMessageEvent;
import jadex.bdi.runtime.Plan;
import jadex.bdi.runtime.Plan.SyncResultListener;
import jadex.bridge.IComponentIdentifier;
import jadex.bridge.fipa.FIPAMessageType;
import jadex.bridge.fipa.SFipa;
import jadex.bridge.service.types.cms.CMSComponentDescription;
import jadex.extension.envsupport.environment.ISpaceAction;
import jadex.extension.envsupport.environment.ISpaceObject;
import jadex.extension.envsupport.environment.space2d.Grid2D;
import jadex.extension.envsupport.environment.space2d.Space2D;
import jadex.extension.envsupport.math.IVector2;
import jadex.extension.envsupport.math.Vector2Int;

public class PlanoReceberMensagem extends Plan {
	@Override
	public void body() {
		if ((Boolean)getBeliefbase().getBelief("message_system").getFact()){
			IMessageEvent me = (IMessageEvent)getReason();
			HashMap<IVector2, Integer> conteudo=(HashMap<IVector2, Integer>)me.getParameter(SFipa.CONTENT).getValue();
			BaseConhecimento bc=(BaseConhecimento) getBeliefbase().getBelief("knows").getFact();
			for (IVector2 k:conteudo.keySet()) {
				
				bc.updateDados(k, new BaseConhecimento.Caixote((int)getClock().getTick(),conteudo.get(k).intValue(),conteudo.get(k).intValue()));
				getBeliefbase().getBelief("knows").setFact(bc);
			}
		}
	}
	
}
